package com.pashanhoo.Thread;

/**
 * @author 胡庆安
 * @version V1.0
 * @Package com.pashanhoo.Thread
 * @date 2020/10/22 15:41
 * @Copyright © 2010-2020 爬山虎科技（扬州）股份有限公司
 */
public class TestLock {
    public static void main(String[] args) {
        HqaLock lock = new HqaLock();
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                lock.lock();
                System.out.println("11111111111");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("1111gggggggg");
                try {
                    lock.unlock();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        },"t1");
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                lock.lock();
                System.out.println("22222222222");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("2222gggggggg");
                try {
                    lock.unlock();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        },"t2");
        t1.start();
        try {
            Thread.sleep(2500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t2.start();
    }
}
